package com.feeyo.groundservice.checkin.constant

import android.app.Activity
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableLongState
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.unit.dp
import com.feeyo.groundservice.base_util.getZeroTime
import com.feeyo.groundservice.checkin.dlg.AddCheckInPopView
import com.feeyo.groundservice.checkin.dlg.CheckInDetailRightAttachPop
import com.feeyo.groundservice.checkin.model.CheckInPerSonBO
import com.feeyo.groundservice.checkin.model.CheckInTaskBO
import com.feeyo.groundservice.checkin.model.CheckInTimeBO
import com.feeyo.groundservice.checkin.model.LinkUserTaskBO
import com.feeyo.groundservice.composewidget.view.tab.TabRowItem
import com.lxj.xpopup.XPopup
import com.lxj.xpopup.enums.PopupPosition

/**
 *作者：70893 on 2025-10-23
 *描述：
 */

/**值机Tab**/
internal fun getCheckInTabMenus() = CheckInStatusType.entries.map {
    TabRowItem(title = it.title, mutableIntStateOf(0))
}

/**值机时间刻度列表**/
internal fun getCheckInTimes(currentTime: Long): List<CheckInTimeBO> {
    //以当前时间为基准，前后各一天，刻度精确到分钟，相当于1分钟为一个dp，从最左边的时间为0dp开始
    val timeOffset = 4 * 60 * 60//秒,生产日偏移量
    val todayZero = currentTime.getZeroTime()//当天零点 s
    val startTime = todayZero - 24 * 3600 + timeOffset//开始时间边界
    val endTime = todayZero + 2 * 24 * 3600 + timeOffset//结束时间边界

    val list = mutableListOf<CheckInTimeBO>()
    //以分钟为刻度,只保存整点数据，其余的使用的时候通过计算获取
    for (time in startTime..endTime step 3600) {
        val timeHM = CheckInTimeBO(time, 0f)
        list.add(timeHM)
    }

    return list

}


/**值机详情**/
fun Activity.showCheckInDetailRightAttach() {
    XPopup.Builder(this)
        .isDestroyOnDismiss(true)
        //.hasBlurBg(true)//背景模糊
        .hasShadowBg(true)//背景色
        .popupPosition(PopupPosition.Right)//右边
        .hasStatusBarShadow(false)
        .asCustom(CheckInDetailRightAttachPop(this))
        .show()
}

/**添加值机**/
fun Activity.showAddCheckInPop(
    user: CheckInPerSonBO,
) {
    XPopup.Builder(this)
        .isDestroyOnDismiss(true)
        .dismissOnBackPressed(false)
        .dismissOnTouchOutside(true)
        .hasShadowBg(true)//背景色
        .asCustom(AddCheckInPopView(this).apply {
            setUser(user)
        })
        .show()
}


/**是否当班**/
fun Int.isDuty(): Boolean = this in listOf(
    DutyType.Duty.type, DutyType.Behalf.type, DutyType.WorkOvertime.type
)